Array.from( )


Posted by mijouhsieh on 2023-03-29

Array.from() return 新陣列

Array.from()方法會從類陣列(array-like)可迭代(iterable)物件 建立一個新的 Array 實體。

console.log(Array.from('foo'));
// Expected output: Array ["f", "o", "o"]

console.log(Array.from([1, 2, 3], x => x + x));
// Expected output: Array [2, 4, 6]
const tiles = Array.from(document.querySelectorAll('.tile'))

#iterable-object #array-like #convert to array







Related Posts

OOP 10 - 回顧抽象、封裝、繼承、多型

OOP 10 - 回顧抽象、封裝、繼承、多型

[評價] Philips 飛利浦 HX3216 電動牙刷

[評價] Philips 飛利浦 HX3216 電動牙刷

【JS幼幼班】Step.06 基本語法:基本型別(string、symbol)

【JS幼幼班】Step.06 基本語法:基本型別(string、symbol)


Comments